package com.xiefengf.elasticsearch.elasticearch_template;

import com.xiefengf.es.Product;
import com.xiefengf.es.ProductMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author xiefengf
 * @version 1.0
 * @date 2024/3/31 17:24
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class EsTest_Mapper {

    @Resource
    private ProductMapper productMapper;

    @Test
    public void test1(){
        for (Product next : productMapper.findAll()) {
            System.out.println(next);
        }
    }

    @Test
    public void test2(){
        Page<Product> category = productMapper.findByCategory("手机",PageRequest.of(1, 1, Sort.by(Sort.Direction.DESC,"price")));
        int pages = category.getTotalPages();
        for (Product product : category) {
            System.out.println(product);
        }
        System.out.println(pages);
    }

    @Test
    public void test3(){
        List<Product> productList = productMapper.findByConditions("手环", "三星电视",3099.0,7000.0);
        for (Product product : productList) {
            System.out.println(product);
        }
    }

    @Test
    public void test4(){
        List<Product> list = productMapper.getByIds(Arrays.asList("1001","1003","1005"));
        for (Product product : list) {
            System.out.println(product);
        }
    }


}
